﻿using UnityEngine;
using System.Collections;

/// <summary>
/// 转换工具
/// </summary>
public class TransferUtils
{

    /// <summary>
    /// 从屏幕坐标转换成世界坐标
    /// </summary>
    /// <param name="screenPos"></param>
    /// <param name="tag"></param>
    /// <returns></returns>
    public static Vector3 ScreenPoitToWorldPos(Vector2 screenPos, string tag)
    {
        Ray ray = Camera.main.ScreenPointToRay(screenPos);
        RaycastHit hitInfo;
        Physics.Raycast(ray, out hitInfo);
        if ((hitInfo.collider != null && hitInfo.collider.tag == tag))
        {
            return hitInfo.point;
        }

        return Vector3.zero;
    }
}
